-
Notifications
You must be signed in to change notification settings - Fork 3.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[dart] fix toString() method generated for enum value #8260
base: master
Are you sure you want to change the base?
Conversation
code += " switch (value) {\n"; | ||
for (auto it = enum_def.Vals().begin(); it != enum_def.Vals().end(); ++it) { | ||
auto &ev = **it; | ||
const auto enum_var = namer_.Variant(ev); | ||
code += " case " + enum_def.ToString(ev) + ": return \"" + enum_var + | ||
"\";\n"; | ||
} | ||
code += " default: return \"\";\n"; | ||
code += " }\n"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The proposed format loses the information about the containing enum. What's the reasoning behind that proposal?
Also, if we should change this, i'd suggest aligning with dart Enum toString() instead:
enum Color { red, green, blue }
main() {
test('test', () {
expect(Color.red.toString(), 'Color.red');
});
}
Additionally, that would seem like a good time to switch to actual enums. Do you think we'd be able to do all that's needed to construct in the scope of flatbuffers if we use enhanced enum syntax?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Update: I've looked into enhanced enums and it works fine, even with the default toString. I'll prep a PR.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current code already handles that and throws in such a case: throw StateError('Invalid value $value for bit flag enum Abc');
. Whether that's the best thing to do is a different topic.
the behavior remains unchanged after the change to enhanced enums (#8313)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
See what others think. If the new PR is merged, I will close this PR
example fbs file:
before change:
after change: